package InetAddress_;

import java.net.InetAddress;

/**
 * @author 宋鑫宇
 * @version 1.0
 */
public class InetAddress01 {
    public static void main(String[] args) throws Exception{
        //1.获取本机地址对象。
        InetAddress ip1 = InetAddress.getLocalHost();
        System.out.println(ip1.getHostName());
        System.out.println(ip1.getHostAddress());
        //2.获取域名ip对象
        InetAddress ip2 = InetAddress.getByName("www.baidu.com");
        System.out.println(ip2.getHostName());
        System.out.println(ip2.getHostAddress());
        //3.获取公网ip对象
        InetAddress ip3 = InetAddress.getByName("39.156.66.14");
//        System.out.println(ip3.getHostName());
        //4.判断是否鞥通过，ping 5秒之前是否可以通过
        System.out.println(ip3.isReachable(5000));
    }
}
